package com.hrbxlh.util;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * -------------------------------------------------------
 * Copyright (c) 2018, 鑫联华信息科技股份有限公司
 * All rights reserved.
 * FileName：AuthImage.java
 * Description：生成验证码
 * History：
 * Date           Author               Desc
 * -------------------------------------------------------
 */
public class AuthImage extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
    static final long serialVersionUID = 1L;

    public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setContentType("image/jpeg");

        //生成随机字串
        String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
        HttpSession session = request.getSession(true);
        session.removeAttribute("randomString");
        session.setAttribute("randomString", verifyCode.toLowerCase());
        //生成图片
        int w = 100, h = 40;
        VerifyCodeUtils.outputImage(w, h, verifyCode, response);
    }
}
